<template>
  <div class="safetyMonitor">
    <stitle :bg="bg" text="罐区实时安全监控" @sclick="sclickhandle" />
    <div class="tablecon">
      <div class="thead">
        <span
          class="thead-item"
          v-for="(item, index) in table.thead"
          :key="index"
          >{{ item }}</span
        >
      </div>
      <div class="tdata">
        <div class="tdatascl">
          <div
            class="tdata-item"
            v-for="(item, index) in table.tdata"
            :key="index"
          >
            <span class="index">{{ item.index }}</span>
            <span class="kpa">{{ item.kpa }}</span>
            <span class="temp">{{ item.temp }}</span>
            <span class="level">{{ item.level }}</span>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import stitle from "@/components/common/stitle";
import {
  createPoi,
  delPoi,
  addFire,
  TwoPointsDistance,
  optimalRoute,
  ViewJump,
  removeLine
} from "@/utils/map";
import { pointProp } from "@/assets/js/pointProp";
export default {
  name: "safetyMonitor",
  components: {
    stitle,
  },
  data() {
    return {
      bg: require("@/assets/images/DispatchCommand/safetyMonitor.png"),
      table: {
        thead: ["罐号", "压力（ Kpa ）", "温度（ ℃ ）", "液位（ m ）"],
        tdata: [
          {
            index: "1号",
            kpa: "0.01",
            temp: "13.4",
            level: "2.162",
          },
          {
            index: "1号",
            kpa: "0.01",
            temp: "13.4",
            level: "2.162",
          },
          {
            index: "1号",
            kpa: "0.01",
            temp: "13.4",
            level: "2.162",
          },
          {
            index: "1号",
            kpa: "0.01",
            temp: "13.4",
            level: "2.162",
          },
          {
            index: "1号",
            kpa: "0.01",
            temp: "13.4",
            level: "2.162",
          },
          {
            index: "1号",
            kpa: "0.01",
            temp: "13.4",
            level: "2.162",
          },
          {
            index: "1号",
            kpa: "0.01",
            temp: "13.4",
            level: "2.162",
          },
          {
            index: "1号",
            kpa: "0.01",
            temp: "13.4",
            level: "2.162",
          },
          {
            index: "1号",
            kpa: "0.01",
            temp: "13.4",
            level: "2.162",
          },
          {
            index: "1号",
            kpa: "0.01",
            temp: "13.4",
            level: "2.162",
          },
          {
            index: "1号",
            kpa: "0.01",
            temp: "13.4",
            level: "2.162",
          },
          {
            index: "1号",
            kpa: "0.01",
            temp: "13.4",
            level: "2.162",
          },
          {
            index: "1号",
            kpa: "0.01",
            temp: "13.4",
            level: "2.162",
          },
          {
            index: "1号",
            kpa: "0.01",
            temp: "13.4",
            level: "2.162",
          },
          {
            index: "1号",
            kpa: "0.01",
            temp: "13.4",
            level: "2.162",
          },
          {
            index: "1号",
            kpa: "0.01",
            temp: "13.4",
            level: "2.162",
          },
          {
            index: "1号",
            kpa: "0.01",
            temp: "13.4",
            level: "2.162",
          },
          {
            index: "1号",
            kpa: "0.01",
            temp: "13.4",
            level: "2.162",
          },
          {
            index: "1号",
            kpa: "0.01",
            temp: "13.4",
            level: "2.162",
          },
        ],
      },
      isclick: false,
      firePosition: {
        x: 120.51801094165354,
        y: 30.604078269915963,
      },
    };
  },
  methods: {
    sclickhandle() {
      if (!this.isclick) {
        let _arr = [
          {
            y: 30.603209487036516,
            x: 120.5172458246754,
            monitorName: "消防站1",
            peopleNum: 153,
          },
          {
            y: 30.60227536721127,
            x: 120.51703324505124,
            monitorName: "消防站2",
            peopleNum: 78,
          },
          {
            y: 30.60224467334593,
            x: 120.5188184547613,
            monitorName: "消防站3",
            peopleNum: 92,
          },
        ];
        this.GLOBAL.poiContainer["FireStation"] = [];
        _arr.forEach((item) => {
          createPoi(pointProp["FireStation"].prop(item));
        });
        addFire();
        //遍历循环消防站，算出距离火灾最近的消防站
        var disList = [];
        _arr.forEach((item) => {
          var dis = TwoPointsDistance(item, this.firePosition);
          disList.push({
            name: item.monitorName,
            dis: dis.distance,
            x: item.x,
            y: item.y,
          });
        });
        disList = disList.sort(this.sortData);
        //视角跳转
         setTimeout(() => {
           ViewJump();
        }, 5000);
        //计算最优路径并且进行绘制最优路线
        setTimeout(() => {
           optimalRoute(disList[0], this.firePosition);
        }, 3000);
       

        this.isclick = true;
      } else {
        delPoi("FireStation");
        if (this.GLOBAL.poiLayerObj) {
          this.GLOBAL.poiLayerObj.deleteObject();
        }
        if (this.GLOBAL.fireObj) {
          this.GLOBAL.fireObj.deleteObject();
        }
        removeLine();
        this.isclick = false;
      }
    },
    //数组对象从小到大排序
    sortData(a, b) {
      return a.dis - b.dis;
    },
  },
  mounted() {},
  computed: {},
};
</script>

<style lang="scss"  scoped>
.safetyMonitor {
  width: 450px;
  padding-right: 70px;
  box-sizing: border-box;
  .tablecon {
    width: 100%;
    max-height: 700px;
    color: #fff;
    margin-top: 20px;
    .thead {
      width: 100%;
      height: 35px;
      display: flex;
      justify-content: space-around;
      color: #0080ff;
      font-weight: bold;
      font-family: ZZGFLQ;
    }
    .tdata {
      width: 100%;
      padding: 10px 0px;
      box-sizing: border-box;
      background-image: url("~@/assets/images/DispatchCommand/tdata.png");
      background-repeat: no-repeat;
      background-size: 100% 100%;
      .tdatascl {
        width: 100%;
        max-height: 650px;
        overflow-y: auto;
        .tdata-item {
          display: flex;
          justify-content: space-around;
          width: 100%;
          height: 40px;
          line-height: 40px;
        }
      }

      .tdatascl::-webkit-scrollbar {
        /*滚动条整体样式*/
        width: 2px;
        /*高宽分别对应横竖滚动条的尺寸*/
        height: 1px;
      }
      .tdatascl::-webkit-scrollbar-thumb {
        /*滚动条里面小方块*/
        border-radius: 10px;
        box-shadow: inset 0 0 5px rgba(0, 0, 0, 0.2);
        background: rgba(0, 160, 233, 0.3);
      }
    }
  }
}
</style>